package db.utils;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * @author DGW-PC
 * @date   2017年9月11日
 */
public class MybatisUtils {
	
	private static SqlSession sqlSession;
	
	public static void getSqlSession() throws IOException {
		
		Reader reader = Resources.getResourceAsReader("mabstis.xml");
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
		sqlSession = factory.openSession(true);
	}
	
	public void closeSession() {
		if (sqlSession!=null) {
			sqlSession.close();
		}
	}
	

}
